blob: 0cb80c3fd2d350f3f2fba24d3283750cbd2bd38a [file] [log] [blame]
Aditya Choudhary51f97c12023-11-02 11:18:40 +00001package main
2
3import (
4 "fmt"
5 "io/ioutil"
6 "os/exec"
7 "strings"
8 "testing"
9)
10
11func TestMetadata(t *testing.T) {
12 cmd := exec.Command(
13 "metadata", "-inputFile", "./inputFiles.txt", "-outputFile",
14 "./generatedOutputFile.txt",
15 )
16 stderr, err := cmd.CombinedOutput()
17 if err != nil {
18 t.Fatalf("Error running metadata command: %s. Error: %v", stderr, err)
19 }
20
21 // Read the contents of the expected output file
22 expectedOutput, err := ioutil.ReadFile("./expectedOutputFile.txt")
23 if err != nil {
24 t.Fatalf("Error reading expected output file: %s", err)
25 }
26
27 // Read the contents of the generated output file
28 generatedOutput, err := ioutil.ReadFile("./generatedOutputFile.txt")
29 if err != nil {
30 t.Fatalf("Error reading generated output file: %s", err)
31 }
32
33 fmt.Println()
34
35 // Compare the contents
36 if string(expectedOutput) != string(generatedOutput) {
37 t.Errorf("Generated file contents do not match the expected output")
38 }
39}
40
41func TestMetadataNegativeCase(t *testing.T) {
42 cmd := exec.Command(
43 "metadata", "-inputFile", "./inputFilesNegativeCase.txt", "-outputFile",
44 "./generatedOutputFileNegativeCase.txt",
45 )
46 stderr, err := cmd.CombinedOutput()
47 if err == nil {
48 t.Fatalf(
49 "Expected an error, but the metadata command executed successfully. Output: %s",
50 stderr,
51 )
52 }
53
54 expectedError := "Conflicting trendy team IDs found for java-test-module" +
55 "-name-one at:\nAndroid.bp with teamId: 12346," +
56 "\nAndroid.bp with teamId: 12345"
57 if !strings.Contains(
58 strings.TrimSpace(string(stderr)), strings.TrimSpace(expectedError),
59 ) {
60 t.Errorf(
61 "Unexpected error message. Expected to contain: %s, Got: %s",
62 expectedError, stderr,
63 )
64 }
65}