github.com/0xKiwi/rules_go@v0.24.3/tests/integration/gazelle/gazelle_test.go (about) 1 // Copyright 2020 The Bazel Authors. All rights reserved. 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 package gazelle_test 16 17 import ( 18 "io/ioutil" 19 "strings" 20 "testing" 21 22 "github.com/bazelbuild/rules_go/go/tools/bazel_testing" 23 ) 24 25 func TestMain(m *testing.M) { 26 bazel_testing.TestMain(m, bazel_testing.Args{ 27 Main: ` 28 -- BUILD.bazel -- 29 load("@bazel_gazelle//:def.bzl", "gazelle") 30 31 # gazelle:prefix example.com/g 32 gazelle( 33 name = "gazelle", 34 ) 35 -- hello.go -- 36 package hello 37 `, 38 WorkspaceSuffix: ` 39 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") 40 41 gazelle_dependencies() 42 `, 43 }) 44 } 45 46 func TestUpdate(t *testing.T) { 47 if err := bazel_testing.RunBazel("run", "//:gazelle"); err != nil { 48 t.Fatal(err) 49 } 50 data, err := ioutil.ReadFile("BUILD.bazel") 51 if err != nil { 52 t.Fatal(err) 53 } 54 got := strings.TrimSpace(string(data)) 55 want := strings.TrimSpace(` 56 load("@io_bazel_rules_go//go:def.bzl", "go_library") 57 load("@bazel_gazelle//:def.bzl", "gazelle") 58 59 # gazelle:prefix example.com/g 60 gazelle( 61 name = "gazelle", 62 ) 63 64 go_library( 65 name = "go_default_library", 66 srcs = ["hello.go"], 67 importpath = "example.com/g", 68 visibility = ["//visibility:public"], 69 ) 70 `) 71 if got != want { 72 t.Errorf("got:\n%s\n\nwant:\n%s", got, want) 73 } 74 }