aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber/customer-tests/update-contextkit-providers/test.sh
blob: 7f800ce28acf3dbb5ab099efff0f7fe3a17f3fad (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
#!/bin/bash -e

export CONTEXT_CORE_DECLARATIONS=/dev/null
export CONTEXT_PROVIDERS=./

# Remove all temp files
function clean {
    `rm -f *.actual`
    `rm -f *.cdb`
}

# Compare file $1 to $2 and display diff if different
function compare {
    f=`diff -u "$1" "$2"`
    if [ $? != 0 ] ; then
        echo "$1 and $2 differ!"
        echo "$f"
        clean
        exit 128
    fi
}

# Query the database $1 using the cdb tool and echo results to $1.actual
function querydb {
    cdb -q "cache.cdb" "$1" > "$2.actual"
}

# Check the keys in the existing cache.cdb database
function dotest {
    querydb "KEYS" "KEYS"
    compare "KEYS.expected" "KEYS.actual"

    querydb "Battery.Charging:KEYTYPE" "Battery.Charging_KEYTYPE"
    compare "Battery.Charging_KEYTYPE.expected" "Battery.Charging_KEYTYPE.actual"

    querydb "Battery.Charging:KEYDOC" "Battery.Charging_KEYDOC"
    compare "Battery.Charging_KEYDOC.expected" "Battery.Charging_KEYDOC.actual"

    querydb "Battery.Charging:PROVIDERS" "Battery.Charging_PROVIDERS"
    compare "Battery.Charging_PROVIDERS.expected" "Battery.Charging_PROVIDERS.actual"
}

# Ensure that the cache file permissions are ok
function checkperm {
    perms=`stat -c %a cache.cdb`
    if [ "$perms" != "644" ] ; then
        echo "Permissions of cache.db are not 644!"
        clean
        exit 128
    fi
}

BASEDIR=`dirname $0`

# Test using command line param
export CONTEXT_PROVIDERS="/tmp/wrong/path"
../../update-contextkit-providers/.libs/update-contextkit-providers "./"
dotest
checkperm
clean

# Test using env var 
export CONTEXT_PROVIDERS="./"
../../update-contextkit-providers/.libs/update-contextkit-providers
dotest
checkperm
clean

echo "All ok!"
exit 0