-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdependency_graph_test.go
More file actions
86 lines (80 loc) · 2.18 KB
/
Copy pathdependency_graph_test.go
File metadata and controls
86 lines (80 loc) · 2.18 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package sdk
import (
"bufio"
"bytes"
"fmt"
"os"
"slices"
"strings"
"testing"
)
// TestSdkArtifactModulePionVersionsMatchRoot prevents the native and browser
// artifact builders from silently compiling an older WebRTC/ICE/SCTP graph
// than the main SDK. Replacements in a dependency module are not inherited,
// and every nested module has its own go.mod/go.sum release boundary.
func TestSdkArtifactModulePionVersionsMatchRoot(t *testing.T) {
rootVersions := testingPionModuleVersions(t, "go.mod")
for _, modulePath := range []string{
"build/go.mod",
"cgo/go.mod",
"js/go.mod",
} {
artifactVersions := testingPionModuleVersions(t, modulePath)
if diff := testingModuleVersionDiff(rootVersions, artifactVersions); diff != "" {
t.Errorf("%s Pion dependency graph differs from the SDK root:\n%s", modulePath, diff)
}
}
}
func testingPionModuleVersions(t *testing.T, path string) map[string]string {
t.Helper()
content, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
versions := map[string]string{}
scanner := bufio.NewScanner(bytes.NewReader(content))
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) < 2 || !strings.HasPrefix(fields[0], "github.com/pion/") {
continue
}
versions[fields[0]] = fields[1]
}
if err := scanner.Err(); err != nil {
t.Fatal(err)
}
if len(versions) == 0 {
t.Fatalf("%s contains no Pion module versions", path)
}
return versions
}
func testingModuleVersionDiff(expected map[string]string, actual map[string]string) string {
moduleSet := map[string]bool{}
for module := range expected {
moduleSet[module] = true
}
for module := range actual {
moduleSet[module] = true
}
modules := make([]string, 0, len(moduleSet))
for module := range moduleSet {
modules = append(modules, module)
}
slices.Sort(modules)
var differences strings.Builder
for _, module := range modules {
expectedVersion, expectedOk := expected[module]
actualVersion, actualOk := actual[module]
if expectedOk && actualOk && expectedVersion == actualVersion {
continue
}
fmt.Fprintf(
&differences,
"%s: root=%q artifact=%q\n",
module,
expectedVersion,
actualVersion,
)
}
return differences.String()
}