File: parsing_test.go

package info (click to toggle)
hut 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,088 kB
  • sloc: makefile: 60; sh: 14
file content (56 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (2)
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
package main

import "testing"

func TestParseResourceName(t *testing.T) {
	tests := []struct {
		s        string
		resource string
		owner    string
		instance string
	}{
		{"https://git.sr.ht/~emersion/hut", "hut", "~emersion", "git.sr.ht"},
		{"sr.ht/~emersion/hut", "hut", "~emersion", "sr.ht"},
		{"~emersion/hut", "hut", "~emersion", ""},
		{"hut", "hut", "", ""},
	}

	for _, test := range tests {
		resource, owner, instance := parseResourceName(test.s)
		if resource != test.resource {
			t.Errorf("parseResourceName(%q) resource: expected %q, got %q", test.s, test.resource, resource)
		}
		if owner != test.owner {
			t.Errorf("parseResourceName(%q) owner: expected %q, got %q", test.s, test.owner, owner)
		}
		if instance != test.instance {
			t.Errorf("parseResourceName(%q) instance: expected %q, got %q", test.s, test.instance, instance)
		}
	}
}

func TestParseBuildID(t *testing.T) {
	tests := []struct {
		s        string
		id       int32
		instance string
	}{
		{"https://builds.sr.ht/~emersion/job/1", 1, "builds.sr.ht"},
		{"~emersion/job/1", 1, ""},
		{"job/1", 1, ""},
		{"1", 1, ""},
	}

	for _, test := range tests {
		id, instance, err := parseBuildID(test.s)
		if err != nil {
			t.Errorf("parseBuildID(%q) error: %v", test.s, err)
		}
		if id != test.id {
			t.Errorf("parseBuildID(%q) id: expected %d, got %d", test.s, test.id, id)
		}
		if instance != test.instance {
			t.Errorf("parseBuildID(%q) instance: expected %q, got %q", test.s, test.instance, instance)
		}
	}
}