1// Copyright (C) 2020 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Minimum support of KMI version in Go. Keep in sync with libkver. 16 17package gki 18 19import ( 20 "testing" 21) 22 23func expectValid(t *testing.T, kmi string, expectedApexName string) { 24 t.Helper() 25 got, e := kmiVersionToApexName(kmi) 26 if e != nil { 27 t.Errorf("Expected no error when parsing %q, got %q", kmi, e) 28 } 29 if got != expectedApexName { 30 t.Errorf("Expected kmiVersionToApexName(%q) == %q, got %q", kmi, expectedApexName, got) 31 } 32} 33 34func expectInvalid(t *testing.T, kmi string) { 35 t.Helper() 36 got, e := kmiVersionToApexName(kmi) 37 if e == nil { 38 t.Errorf("Expected error when parsing %q, got no error with result %q", kmi, got) 39 } 40} 41 42func TestParse(t *testing.T) { 43 expectInvalid(t, "") 44 expectInvalid(t, "foobar") 45 expectInvalid(t, "1") 46 expectValid(t, "5.4-android12-0", "com.android.gki.kmi_5_4_android12_0") 47 expectValid(t, "5.4-android12-42", "com.android.gki.kmi_5_4_android12_42") 48} 49