File: parse_test.go

package info (click to toggle)
golang-github-knqyf263-go-dep-parser 0.0~git20190521.1ef8521-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,440 kB
  • sloc: makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download
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
package composer

import (
	"github.com/knqyf263/go-dep-parser/pkg/types"
	"os"
	"path"
	"testing"
)

func TestParse(t *testing.T){
	vectors := []struct {
		file    string // Test input file
		libraries []types.Library
	}{
		{
			file:    "testdata/composer_normal.lock",
			libraries: ComposerNormal,
		},
		{
			file:    "testdata/composer_laravel.lock",
			libraries: ComposerLaravel,
		},
		{
			file:    "testdata/composer_symfony.lock",
			libraries: ComposerSymfony,
		},
		{
			file:    "testdata/composer_with_dev.lock",
			libraries: ComposerWithDev,
		},
	}

	for _, v := range vectors {
		t.Run(path.Base(v.file), func(t *testing.T) {
			f, err := os.Open(v.file)
			if err != nil {
				t.Fatalf("Open() error: %v", err)
			}
			libList, err := Parse(f)
			if err != nil {
				t.Fatalf("Parse() error: %v", err)
			}

			if len(libList) != len(v.libraries) {
				t.Fatalf("lib length: got %v, want %v", len(libList), len(v.libraries))
			}

			for i, got := range libList{
				want := v.libraries[i]
				if want.Name != got.Name {
					t.Errorf("%d: Name: got %s, want %s", i, got.Name, want.Name)
				}
				if want.Version != got.Version {
					t.Errorf("%d: Version: got %s, want %s", i, got.Version, want.Version)
				}
			}
		})
	}
}