github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/legal/extra/extra_test.go (about) 1 package extra 2 3 import ( 4 "flag" 5 "testing" 6 7 "github.com/henvic/wedeploycli/tdata" 8 ) 9 10 var update bool 11 12 func init() { 13 flag.BoolVar(&update, "update", false, "update golden files") 14 } 15 16 func TestLicenseNotFound(t *testing.T) { 17 l := License{ 18 LicensePath: "mocks/not-found", 19 } 20 21 var _, err = l.Get() 22 23 if err == nil { 24 t.Error("Expected error when trying to read mock license file") 25 } 26 } 27 28 func TestLicense(t *testing.T) { 29 l := License{ 30 Name: "mock", 31 Package: "example.com/mock", 32 Notes: "", 33 LicensePath: "mocks/in", 34 } 35 36 var got, err = l.Get() 37 38 if err != nil { 39 t.Errorf("Error reading mock license file: %v", err) 40 } 41 42 if update { 43 tdata.ToFile("mocks/out", string(got)) 44 } 45 46 var want = tdata.FromFile("mocks/out") 47 48 if string(got) != want { 49 t.Errorf("Wanted output to be %v, got %v instead", want, got) 50 } 51 } 52 53 func TestLicenseWithNote(t *testing.T) { 54 l := License{ 55 Name: "mock", 56 Package: "example.com/mock", 57 Notes: "modified", 58 LicensePath: "mocks/in", 59 } 60 61 var got, err = l.Get() 62 63 if err != nil { 64 t.Errorf("Error reading mock license file: %v", err) 65 } 66 67 if update { 68 tdata.ToFile("mocks/out-with-note", string(got)) 69 } 70 71 var want = tdata.FromFile("mocks/out-with-note") 72 73 if string(got) != want { 74 t.Errorf("Wanted output to be %v, got %v instead", want, got) 75 } 76 }