aboutsummaryrefslogtreecommitdiffstats
path: root/main_test.go
blob: b0ede2fa5f182689369e1427f0c847c1e684c1c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import (
	"io/ioutil"
	"os"
	"strings"
	"testing"
)

func TestApp(t *testing.T) {
	fileContent := "package testing\n\nimport \"fmt\"\n\nfunc HelloWorld() {\nfmt.Println(\"Hello World!\")\n}\n"

	ioutil.WriteFile("hello.go", []byte(fileContent), os.ModePerm)

	ProcessFile("hello.go", "fmt", "replacedImport")

	result, err := ioutil.ReadFile("hello.go")
	if err != nil {
		t.Error("Failed to read written file.")
	}

	if !strings.Contains(string(result), "replacedImport") {
		t.Error("Got different results")
	}
	os.Remove("hello.go")
}