summaryrefslogtreecommitdiffstats
path: root/src/qtmoduleupdater/module_test.go
blob: 38d341f684377343b4b45b8a5e2b898c8de8ead8 (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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the repo tools module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
package main

import (
	"bytes"
	"testing"

	"github.com/stretchr/testify/assert"

	yaml "gopkg.in/yaml.v2"
)

func TestModuleYamlMarshalling(t *testing.T) {
	var module YAMLDependencies
	module.Dependencies = make(map[string]*YAMLModule)

	module.Dependencies["a"] = &YAMLModule{
		Ref:      "refs/heads/foo",
		Required: false,
	}
	module.Dependencies["b"] = &YAMLModule{
		Ref:      "refs/heads/bar",
		Required: true,
	}

	output := &bytes.Buffer{}
	encoder := yaml.NewEncoder(output)
	encoder.Encode(&module)
	encoder.Close()

	yamlStr := output.String()

	assert.Equal(t, `dependencies:
  a:
    ref: refs/heads/foo
    required: false
  b:
    ref: refs/heads/bar
    required: true
`, yamlStr, "Yaml output should be as expected")
}

func TestProposedUpdateFailsForModulesThatDependOnMoreThanQtBase(t *testing.T) {
	// Make sure that this always points to the latest LTS branch. If it fails, update it.
	ref := "refs/heads/5.12"
	qt5Modules, err := getQt5ProductModules("qt/qt5", ref, "")

	assert.Nil(t, err, "Retrieving qt5 modules expected to work")

	todoMap, availableModules, err := loadTodoAndDoneModuleMapFromSubModules(ref, qt5Modules)
	assert.Nil(t, err, "No error expected creating module map")

	_, ok := availableModules["qt/qtbase"]
	assert.True(t, ok, "qt/qtbase must be present in the module map")

	qtSvg, ok := todoMap["qt/qtsvg"]
	assert.True(t, ok, "qtsvg must be present in the module map")
	yamlObject, err := qtSvg.maybePrepareUpdatedDependenciesYaml(availableModules)
	assert.NotNil(t, yamlObject, "Yaml object must be defined for qtsvg")

	yamlStr := &bytes.Buffer{}
	encoder := yaml.NewEncoder(yamlStr)
	encoder.Encode(*yamlObject)
	encoder.Close()

	assert.Nil(t, err, "It should be possible to create a new dependencies.yaml file for qtsvg")
	assert.NotEqual(t, "", yamlStr, "Yaml string must not be empty for qtsvg")

	qtDeclarative, ok := todoMap["qt/qtdeclarative"]
	assert.True(t, ok, "qtdeclarative must be present in the module map")
	yamlObject, err = qtDeclarative.maybePrepareUpdatedDependenciesYaml(availableModules)

	assert.Nil(t, err, "It should be possible to create a new dependencies.yaml file for qtdeclarative")
	assert.Nil(t, yamlObject, "Yaml string be empty for qtdeclarative because dependencies are not available yet")
}

func TestRemovalOfNonExistentOptionalDependencies(t *testing.T) {
	// Make sure that this always points to the latest LTS branch. If it fails, update it.
	ref := "refs/heads/5.12"
	qt5Modules, err := getQt5ProductModules("qt/qt5", ref, "")
	assert.Nil(t, err, "Retrieving qt5 modules expected to work")

	_, haveSvg := qt5Modules["qt/qtsvg"]
	assert.True(t, haveSvg, "qtsvg needs to be in qt5.git")
	delete(qt5Modules, "qt/qtsvg")

	qtDeclarative := qt5Modules["qt/qtdeclarative"]
	assert.NotNil(t, qtDeclarative, "need qtdeclarative")

	assert.Contains(t, qtDeclarative.optionalDependencies, "qt/qtsvg")
	qtDeclarativeModule, err := NewModule("qt/qtdeclarative", ref, qt5Modules)
	assert.Nil(t, err, "There shall not be any error creating the module")

	assert.NotNil(t, qtDeclarativeModule, "qtdeclarative module shall exist")

	assert.Contains(t, qtDeclarativeModule.RequiredDependencies, "qt/qtbase")
	assert.NotContains(t, qtDeclarativeModule.OptionalDependencies, "qt/qtsvg")
}

func TestQueryChangeStatus(t *testing.T) {
	status, err := getGerritChangeStatus("qt/qtbase", "dev", "Ie6f0e2e3bb198a95dd40e7416adc8ffb29f3b2ba")
	assert.Nil(t, err, "Querying should not produce an error")
	assert.Equal(t, "MERGED", status)

	status, err = getGerritChangeStatus("qt/qtbase", "dev", "I6e4349f4d72de307a579f59bb689fd0638690403")
	assert.Nil(t, err, "Querying should not produce an error")
	assert.Equal(t, "ABANDONED", status)

}