github.com/konsorten/ktn-build-info@v1.0.11/ver/helpers_test.go (about) 1 package ver 2 3 import ( 4 "io" 5 "os" 6 "testing" 7 ) 8 9 func copyFile(t *testing.T, fromPath string, toPath string) { 10 from, err := os.Open(fromPath) 11 12 if err != nil { 13 t.Fatal(err) 14 } 15 16 defer from.Close() 17 18 to, err := os.Create(toPath) 19 20 if err != nil { 21 t.Fatal(err) 22 } 23 24 defer to.Close() 25 26 _, err = io.Copy(to, from) 27 28 if err != nil { 29 t.Fatal(err) 30 } 31 } 32 33 func createTestVersionInformationFromYAML(t *testing.T) *VersionInformation { 34 // read host information 35 host, err := TryReadFromBuildHost() 36 37 if err != nil { 38 t.Fatalf("Failed to read build host info: %v", err) 39 } 40 41 // read version information 42 found, err := TryReadFromVersionInfoYAML(0) 43 44 if err != nil { 45 t.Fatalf("Failed to read version info: %v", err) 46 } 47 48 if found == nil { 49 t.Fatalf("%v not found", VersionInfoYamlFilename) 50 } 51 52 found.CopyMissingFrom(host) 53 found.Build = 4 54 found.Revision = "abcdef0" 55 56 if ok, _ := found.IsValid(); !ok { 57 t.Fatal("Invalid version information") 58 } 59 60 return found 61 }