github.com/april1989/origin-go-tools@v0.0.32/internal/lsp/mod/mod_test.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mod 6 7 import ( 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 "testing" 12 13 "github.com/april1989/origin-go-tools/internal/lsp/cache" 14 "github.com/april1989/origin-go-tools/internal/lsp/tests" 15 "github.com/april1989/origin-go-tools/internal/span" 16 "github.com/april1989/origin-go-tools/internal/testenv" 17 ) 18 19 func TestMain(m *testing.M) { 20 testenv.ExitIfSmallMachine() 21 os.Exit(m.Run()) 22 } 23 24 func TestModfileRemainsUnchanged(t *testing.T) { 25 testenv.NeedsGo1Point(t, 14) 26 27 ctx := tests.Context(t) 28 cache := cache.New(ctx, nil) 29 session := cache.NewSession(ctx) 30 options := tests.DefaultOptions() 31 options.TempModfile = true 32 options.Env = append(os.Environ(), "GOPACKAGESDRIVER=off", "GOROOT=") 33 34 // Make sure to copy the test directory to a temporary directory so we do not 35 // modify the test code or add go.sum files when we run the tests. 36 folder, err := tests.CopyFolderToTempDir(filepath.Join("testdata", "unchanged")) 37 if err != nil { 38 t.Fatal(err) 39 } 40 defer os.RemoveAll(folder) 41 42 before, err := ioutil.ReadFile(filepath.Join(folder, "go.mod")) 43 if err != nil { 44 t.Fatal(err) 45 } 46 _, _, release, err := session.NewView(ctx, "diagnostics_test", span.URIFromPath(folder), options) 47 release() 48 if err != nil { 49 t.Fatal(err) 50 } 51 after, err := ioutil.ReadFile(filepath.Join(folder, "go.mod")) 52 if err != nil { 53 t.Fatal(err) 54 } 55 if string(before) != string(after) { 56 t.Errorf("the real go.mod file was changed even when tempModfile=true") 57 } 58 }